<?php
namespace app\admin\model;
use think\Loader;
use think\Model;
use think\Validate;

class LinkModel extends Model
{
    protected $pk = 'id';//主键
    //设置当前模型对应的完整数据表名称
    protected $table = 'fly_link';
    //后台用户中心数据
    public function linkList()
    {
    	$linkList = $this->select();
    	// dump($userList);die;
    	return $linkList;
    }

    //执行添加友情链接操作
    public function add($data)
    {
    	$validate = new Validate([
            'lname'  => 'require',
            'lurl'  => 'require',
        ],[
            'lname.require'  => '网站名不能为空',
            'lurl.require'  => '网站链接不能为空'
            ]
    );
        if (!$validate->check($data)) {
            return ['valid'=> 0,'msg'=>$validate->getError()];
        }
        
        $res = $this->allowField(true)->save($data);

        if($res){
            return ['valid'=>1, 'msg'=>'添加成功'];
        }else{
            return ['valid'=>0, 'msg'=>'添加失败'];

        }
    }
    // 友情链接的删除
    public function del($data)
    {
        // dump($data);die;
        $res = $this->where('id',$data)->delete();
// db('user')->delete(1);
        if($res){
            return ['valid'=>1, 'msg'=>'删除成功'];
        }else{
            return ['valid'=>0, 'msg'=>'删除失败'];

        }



    }
   


}